import Taro, {Component} from '@tarojs/taro'
import {Provider, connect} from '@tarojs/redux'
import qs from 'qs'

import Index from './pages/index'

import configStore from './store'

import './app.scss'
import { login } from './api/user'
import { getUser } from './actions/user'

// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释：
// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5')  {
//   require('nerv-devtools')
// }

const store = configStore();
const { dispatch } = store

class App extends Component {

  config = {
    pages: [
      'pages/index/index',
      'pages/salary/index',
      'pages/salary/detail/index',
      'pages/guide/index',
      'pages/attendance/index',
      'pages/attendance/replaceCard/index',
      'pages/leave/index',
      'pages/leave/apply/index',
      'pages/sporadicLeave/index',
      'pages/leaveRecording/index',
      'pages/shift/index',
      'pages/shift/apply/index',
      'pages/overtime/index',
      'pages/overtime/apply/index',
      'pages/360score/index',
      'pages/360score/score/index',
      'pages/contract/index',
      'pages/selectUser/index',
      'pages/salaryCard/index',
      'pages/salaryCard/edit/index',
      'pages/socialSecurity/index',
      'pages/socialSecurity/detail/index',
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black'
    }
  }

  componentDidMount() {
    const query = qs.parse(window.location.href.split('?')[1]);
    const { code } = query;
    login(code).then((data) => {
      dispatch(getUser())
    })
  }

  componentDidShow() {
  }

  componentDidHide() {
  }

  componentDidCatchError() {
  }

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render() {
    return (
      <Provider store={store}>
        <Index/>
      </Provider>
    )
  }
}

Taro.render(<App/>, document.getElementById('app'))
